﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SimpleModel.cs" company="XamlNinja">
//   2011 Richard Griffin and Ollie Riches
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace WP7Contrib.Common.Tests.Models
{
    using System;
    using Common;

    public class SimpleModel : BaseModel, IEquatable<SimpleModel>
    {
        private string stringValue;
        private double doubleValue;

        public SimpleModel(string stringValue, double doubleValue)
        {
            this.stringValue = stringValue;
            this.doubleValue = doubleValue;
        }

        public string StringValue
        {
            get
            {
                return this.stringValue;
            }

            set
            {
                this.SetPropertyAndNotify(ref this.stringValue, value, () => this.StringValue);
            }
        }

        public double DoubleValue
        {
            get
            {
                return this.doubleValue;
            }

            set
            {
                this.SetPropertyAndNotify(ref this.doubleValue, value, () => this.DoubleValue);
            }
        }

        public void RaisePropertyChangedEventsUsingExpressionSyntax()
        {
            this.SetPropertyAndNotify(ref this.stringValue, Guid.NewGuid().ToString(), () => this.StringValue);
            this.SetPropertyAndNotify(ref this.doubleValue, DateTime.Now.Ticks, () => this.DoubleValue);
        }

        public void RaisePropertyChangedEventsUsingPropertyNameSyntax()
        {
            System.Threading.Thread.SpinWait(512);
            this.SetPropertyAndNotify(ref this.stringValue, Guid.NewGuid().ToString(), "StringValue");
            this.SetPropertyAndNotify(ref this.doubleValue, DateTime.Now.Ticks, "DoubleValue");
        }

        public static bool operator ==(SimpleModel sm1, SimpleModel sm2)
        {
            return Equals(sm1, sm2);
        }

        public static bool operator !=(SimpleModel sm1, SimpleModel sm2)
        {
            return !Equals(sm1, sm2);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            return obj is SimpleModel && this.Equals((SimpleModel)obj);
        }

        public override int GetHashCode()
        {
            return this.CombineHashCodes(this.StringValue, this.DoubleValue);
        }

        public bool Equals(SimpleModel model)
        {
            if (ReferenceEquals(null, model))
            {
                return false;
            }

            if (this.StringValue != model.StringValue)
            {
                return false;
            }

            if (this.DoubleValue != model.DoubleValue)
            {
                return false;
            }

            return true;
        }
    }
}
